from django.db import models

# Create your models here.

from datetime import datetime


# 用户表
class UserModel(models.Model):
    username = models.CharField(max_length=32)
    mobile = models.CharField(max_length=11)
    password = models.CharField(max_length=256)
    money = models.DecimalField(max_digits=10,decimal_places=2,default=0)
    level=models.IntegerField(verbose_name='等级',default=0)
    lock_money = models.DecimalField(max_digits=10, decimal_places=2, default=0)
    user_type = models.IntegerField(default=0,verbose_name='1 雇主 2 服务商')
    status = models.IntegerField(default=0, verbose_name='0 默认 1 会员')
    images=models.CharField(max_length=256,default='')
    create_time = models.DateTimeField(default=datetime.now())

    def __str__(self):
        return self.username

    class Meta:
        db_table = 'user'



# #### 5.三方登录表
# 用户id、三方平台、token、uid，三方平台地址
class SfLogin(models.Model):
    __tablename__="sf_login"
    userid = models.ForeignKey(to=UserModel,  on_delete=models.CASCADE)
    webfrom = models.CharField(max_length=30)
    token = models.CharField(max_length=128)
    uid = models.CharField(max_length=100)
    url = models.CharField(max_length=256)

    def __str__(self):
        return self.userid

    class Meta:
        db_table = 'sf_login'



#合同表
class ContractModel(models.Model):
    name = models.CharField(max_length=30)
    content = models.TextField()
    url = models.CharField(max_length=256,default='')
    type = models.IntegerField(default=1)
    def __str__(self):
        return self.name
    class Meta:
        db_table = 'contract'

#用户签订合同
class ContractUserModel(models.Model):
    user_id = models.ForeignKey(to=UserModel,  on_delete=models.CASCADE)
    contract_id = models.IntegerField()
    def __str__(self):
        return self.user_id
    class Meta:
        db_table = 'user_contract'


# 企业表
class CompanyModel(models.Model):
    companies_name = models.CharField(max_length=32, verbose_name='企业名称')
    juridical_person = models.CharField(max_length=16, verbose_name='法人',default='')
    code=models.CharField(max_length=100,verbose_name='企业认证码',default='')
    mobile = models.CharField(max_length=11)
    scale=models.CharField(max_length=10)  # 规模
    address = models.CharField(max_length=64, verbose_name='企业地址')

    def __str__(self):
        return self.companies_name
    class Meta:
        db_table = 'company'

# 企业与个人关联表
class CompanyUserModel(models.Model):
    user_id = models.IntegerField()
    companies_id = models.IntegerField()

    def __str__(self):
        return self.user_id
    class Meta:
        db_table = 'company_user'


#用户账户金额记录表
class UserAmount_record(models.Model):
    money = models.DecimalField(max_digits=10, decimal_places=2)
    create_time = models.DateTimeField(default=datetime.now())
    type=models.IntegerField(verbose_name='1 + 2 -')
    status=models.IntegerField(verbose_name='0 充值或提现 1 订单') # 3 购买会员
    user_id = models.IntegerField()

    def __str__(self):
        return self.money
    class Meta:
        db_table = 'user_amount'

#  vip记录表 用户id  开始时间  结束时间
class VipModel(models.Model):
    __tablename__="vip"
    userid = models.ForeignKey(to=UserModel, on_delete=models.CASCADE)
    start_time = models.DateTimeField(default=datetime.now())
    end_time = models.DateTimeField()
# #### vip购买记录订单表

# 用户id、购买年限、金额、折扣、实际第三方支付金额、支付状态
class VipRecordModel(models.Model):
    __tablename__="vip_record"
    order_id=models.CharField(max_length=30,default='')
    userid = models.ForeignKey(to=UserModel, on_delete=models.CASCADE)
    year = models.IntegerField(verbose_name='年',default=1)
    money = models.DecimalField(max_digits=8,decimal_places=2,default=365)
    discount = models.DecimalField(max_digits=8,decimal_places=2,default=0)
    active_money = models.DecimalField(max_digits=8,decimal_places=2,default=365)
    status = models.IntegerField(verbose_name='支付状态 1 正常 2 失败',default=0)
    create = models.DateTimeField(default=datetime.now())

class RechargeModel(models.Model):  # 充值记录表
    order_id = models.CharField(max_length=30, default='')
    userid = models.ForeignKey(to=UserModel, on_delete=models.CASCADE)
    money = models.DecimalField(max_digits=8, decimal_places=2)
    status = models.IntegerField(verbose_name='支付状态 1 正常 2 失败', default=0)
    type = models.IntegerField(verbose_name='平台类型',default=1)
    create = models.DateTimeField(default=datetime.now())
    def __str__(self):
        return self.order_id
    class Meta:
        db_table = 'recharge_model'

class Trade_TypeModel(models.Model):  # 个人行业类型表  只有一二级分类
    name = models.CharField(max_length=30)
    pid = models.IntegerField(verbose_name='自关联')

    def __str__(self):
        return self.name

    class Meta:
        db_table = 'trade_type'

class Classify(models.Model):   # 服务分类表
    name=models.CharField(max_length=30)
    pid=models.IntegerField(verbose_name='无限自关联')
    def __str__(self):
        return self.name
    class Meta:
        db_table = 'classify'

class ProfessionType(models.Model):   # 服务商职业技术分类表
    name = models.CharField(max_length=30)
    pid = models.IntegerField(verbose_name='无限自关联')

    def __str__(self):
        return self.name

    class Meta:
        db_table = 'profession_type'


class User_certification(models.Model):   # 实名认证表
    userid = models.ForeignKey(to=UserModel, on_delete=models.CASCADE)
    name=models.CharField(max_length=30,verbose_name='真实姓名')
    code=models.CharField(verbose_name='身份证id',max_length=30)
    create_time = models.DateTimeField(default=datetime.now())
    class Meta:
        db_table = 'user_certification'

class ProjectDemandModel(models.Model):   # 按项目
    userid = models.ForeignKey(to=UserModel, on_delete=models.CASCADE)
    title=models.CharField(max_length=20,verbose_name='标题')
    describe=models.TextField(verbose_name='需求描述')
    price = models.DecimalField(max_digits=10, decimal_places=2)
    max_price = models.DecimalField(max_digits=10, decimal_places=2)
    need_id = models.IntegerField(verbose_name='需求的标签')
    project_type=models.IntegerField(verbose_name='项目类型')
    way_type=models.IntegerField(verbose_name='方式类型')  # 比稿（自己选择其中一个） 招标（找人）
    review_status = models.IntegerField(default=0, verbose_name='0 未审核 1 审核通过 2 审核未通过')
    create_time = models.DateTimeField(default=datetime.now())
    class Meta:
        db_table = 'project_demand_model'


#订单表
class OrdersModel(models.Model):
    order_code = models.BigIntegerField(primary_key=True)  # 订单号
    user_id = models.IntegerField()   # 雇主
    seller_id = models.IntegerField(verbose_name='卖家id')
    goods_price = models.DecimalField(max_digits=10, decimal_places=2)   # 价钱
    pay_status = models.IntegerField(default=1, verbose_name='1 为未支付 2 为支付完成')  # 支付状态
    create_time = models.DateTimeField(default=datetime.now())
    def __str__(self):
        return self.order_code
    class Meta:
        db_table = 'orders'

#订单历史记录表
class OrderRecordModel(models.Model):
    order_id = models.BigIntegerField()
    user_id = models.IntegerField(verbose_name='买家id')
    order_num = models.BigIntegerField(verbose_name='所属订单')
    seller_id = models.IntegerField(verbose_name='卖家id')
    shop_id = models.IntegerField(default=0,verbose_name='商铺外键')
    goods_count = models.IntegerField()
    goods_price = models.DecimalField(max_digits=10, decimal_places=2)
    create_time = models.DateTimeField(default=datetime.now())

    def __str__(self):
        return self.order_id

    class Meta:
        db_table = 'order_record'



# class ProjectDemandTimeModel(models.Model):   # 按时间计费
#     userid = models.ForeignKey(to=UserModel, on_delete=models.CASCADE)
#     title=models.CharField(max_length=20,verbose_name='标题')
#     describe=models.TextField(verbose_name='需求描述')
#     price = models.DecimalField(max_digits=10, decimal_places=2)
#     need_id = models.IntegerField(verbose_name='需求的标签')
#     project_type=models.IntegerField(verbose_name='类型')
#     review_status = models.IntegerField(default=0, verbose_name='0 未审核 1 审核通过 2 审核未通过')
#     create_time = models.DateTimeField(default=datetime.now())


# class project(BaseModel):
#     __tablename__ = 'project'
#     code = db.Column(db.BIGINT,primary_key=True,nullable=False)
#     name = db.Column(db.String(20),comment='详情')
#     title = db.Column(db.String(20),comment='标题')
#     descs = db.Column(db.String(20),comment='描述')
#     type = db.Column(db.String(50),comment='人才类型')
#     money = db.Column(db.Float,comment='预算')
#     mobile = db.Column(db.String(11),comment='手机号')
#     trade = db.Column(db.String(50),comment='行业')
#     status =db.Column(db.Integer,default=0)
#     userid = db.Column(db.Integer)



# #商家需求表
# class BusinessDemandModel(models.Model):
#     demand_name = models.CharField(max_length=128,verbose_name='商品需求')
#     specific_detail = models.TextField()
#     price = models.DecimalField(max_digits=10,decimal_places=2,default=0)
#     settlement_type = models.IntegerField(default=0, verbose_name='1 为日结 2 为月结 3为完工结')
#     business_type = models.IntegerField(default=0, verbose_name='1 为个人级 2 为企业级')
#     profession_id = models.IntegerField(verbose_name='需求的标签')
#     user_id = models.IntegerField()
#     review_status = models.IntegerField(default=0, verbose_name='0 未审核 1 审核通过 2 审核未通过')
#     create_datetime = models.DateTimeField(default=datetime.now())
#     def __str__(self):
#         return self.demand_name
#     class Meta:
#         db_table = 'business_demand'
#




# #服务商擅长专业表
# class UserProfessionModel(models.Model):
#     user_id = models.IntegerField(default=0)
#     profession_id = models.IntegerField(default=0)
#     def __str__(self):
#         return self.user_id
#     class Meta:
#         db_table = 'user_profession'
#
# #服务商个人详细信息
# class ServiceAbilityModel(models.Model):
#     job_age = models.CharField(max_length=36,verbose_name='工作经验')
#     introduce = models.TextField()
#     user_id = models.IntegerField()
#     create_datetime = models.DateTimeField(default=datetime.now())
#     def __str__(self):
#         return self.user_id
#     class Meta:
#         db_table = 'service_ability'
#

# #用户接单
# class TakeOrderModel(models.Model):
#     user_id = models.IntegerField()
#     business_id = models.IntegerField()
#     create_datetime = models.DateTimeField(default=datetime.now())
#     status = models.IntegerField(default=0,verbose_name='0 未交接 1 已完成 2 未通过')
#     def __str__(self):
#         return self.user_id
#     class Meta:
#         db_table = 'take_order'
#
#
# #商铺表
# class ShopModel(models.Model):
#     shop_name = models.CharField(max_length=32,verbose_name='商铺名')
#     user_id = models.IntegerField()
#     def __str__(self):
#         return self.shop_name
#     class Meta:
#         db_table = 'shop'
#
# #商品表
# class GoodsModel(models.Model):
#     goods_name = models.CharField(max_length=32,verbose_name='商品名')
#     price = models.DecimalField(max_digits=10,decimal_places=2,default=0)
#     images=models.CharField(max_length=256)
#     goods_introduce = models.TextField(verbose_name='商铺介绍')
#     profession_id = models.IntegerField(default=0,verbose_name='商品所属专业类型外键')
#     shop_id = models.IntegerField(verbose_name='商铺外键')
#     user_id = models.IntegerField(verbose_name='商家个人外键')
#     def __str__(self):
#         return self.goods_name
#     class Meta:
#         db_table = 'goods'
#
# #购物车表
# class ShoppingCartModel(models.Model):
#     user_id = models.IntegerField()
#     shop_id = models.IntegerField()
#     goods_id = models.IntegerField()
#     goods_count = models.IntegerField()
#     goods_price = models.DecimalField(max_digits=10,decimal_places=2)
#     def __str__(self):
#         return self.user_id
#     class Meta:
#         db_table = 'shopping_cart'
#
#
# #订单表
# class OrderModel(models.Model):
#     order_num = models.BigIntegerField(primary_key=True)
#     user_id = models.IntegerField()
#     seller_id = models.IntegerField(verbose_name='卖家id')
#     goods_price = models.DecimalField(max_digits=10, decimal_places=2)
#     pay_status = models.IntegerField(default=1, verbose_name='1 为未支付 2 为支付完成')
#     create_time = models.DateTimeField(default=datetime.now())
#     def __str__(self):
#         return self.order_num
#     class Meta:
#         db_table = 'order'
#
# #订单历史记录表
# class OrderRecordModel(models.Model):
#     order_id = models.BigIntegerField()
#     user_id = models.IntegerField(verbose_name='买家id')
#     order_num = models.BigIntegerField(verbose_name='所属订单')
#     seller_id = models.IntegerField(verbose_name='卖家id')
#     shop_id = models.IntegerField(default=0,verbose_name='商铺外键')
#     goods_count = models.IntegerField()
#     goods_price = models.DecimalField(max_digits=10, decimal_places=2)
#     create_time = models.DateTimeField(default=datetime.now())
#
#     def __str__(self):
#         return self.order_id
#
#     class Meta:
#         db_table = 'order_record'






























